package com.cartoon.service.impl;

import java.util.Collections;
import java.util.Comparator;
import java.util.List;

import com.cartoon.bean.Cartoon;
import com.cartoon.dao.CarDao;
import com.cartoon.dao.impl.CarDaoImpl;
import com.cartoon.service.CartService;

public class CarServiceImpl implements CartService{
private CarDao cd = new CarDaoImpl();
	/**
	 *查询全部书名
	 */
	@Override
	public List<Cartoon> selectAllcar() {
		return cd.selectAllCartoon();
	}
	/**
	 *模糊查询
	 */
	@Override
	public List<Cartoon> selectlike(String carname) {
		return cd.like(carname);
	}
	/**
	 *添加书籍 1添加成功 0 添加失败
	 */
	@Override
	public int addart(String carName, String CarRelease, String carType, int carVisito, String carSummary,
			String carImg, int carLike, int carUpdate, int carFree, int carEnd, int carPiao, int carPublish,
			int carSigning, int carSelling) {
		return cd.addcart(carName, CarRelease, carType, carVisito, carSummary, carImg, carLike, carUpdate, carFree, carEnd, carPiao, carPublish, carSigning, carSelling);
	}
	/**
	 *删除书籍 1成功 0失败
	 */
	@Override
	public int deletcart(String cartName) {
		return cd.deletecart(cartName);
	}
	/**
	 *修改漫画 1成功 0失败
	 */
	@Override
	public int updatecart(Cartoon Cartoon) {
		return 0;
	}
	/**
	 * 查询 null 没有
	 */
	@Override
	public List<Cartoon> selectByqyue(int signing) {
		return cd.selectByqyue(signing);
	}
	/**
	 * null 没有种类型的图书
	 */
	@Override
	public List<Cartoon> selectByselling(int selling) {
		return cd.selectByselling(selling);
	}
	/**
	 *通过是否免费来查询漫画
	 */
	@Override
	public List<Cartoon> selectByfree(String free) {
		return cd.selectByfree(free);
	}
	/**
	 *通过是否完结来查询漫画
	 */
	@Override
	public List<Cartoon> selectByend(String endof) {
		return cd.selectByend(endof);
	}
	/**
	 *通过男性向还是女性向来查询漫画
	 */
	@Override
	public List<Cartoon> selectBysex(String sex) {
		return cd.selectBysex(sex);
	}
	
	/**
	 *通过月票排序大到小
	 */
	@Override
	public List<Cartoon> selectBypiao() {
		List<Cartoon> list= cd.selectBycartPiao();
		Collections.sort(list,new Comparator<Cartoon>(){

			@Override
			public int compare(Cartoon o1, Cartoon o2) {
				if(o1.getCartPiao() > o2.getCartPiao()) {
					return -1;
				}
				if(o1.getCartPiao() == o2.getCartPiao()) {
					return 0;
				}
				return 1;
			}
			
			
		});
		return list;
	}

	
}
